<template>
  <div>
		<el-scrollbar class="app-container-scroll-bar">
        <listTpml :data="pageData" @onCommand="handleCommand" ref="listTpml"></listTpml>
    </el-scrollbar>


     <!-- 新增角色弹窗 -->
    <add-j-s-dialog ref="addjs" @addSucess="refresh"> 
    </add-j-s-dialog>
  </div>
</template>



<script>
import listTpml from "@/view/components/listTmpl";
import addJSDialog from '@/view/pages/xitong/juese/addJS.vue';
import {deleteRole} from '@/service/swagger/RoleController.js'

  export default{
    components:{
      listTpml,
      addJSDialog
    },
    data(){
      return{
        pageData: {
          pageTitle: "角色管理",
          // 列表table 设置
          listOption: {
            // 列表上部btn组
            listBtns: [
              {
                label: "新建角色",
                iconfont: "icon-folder-add",
                commandName: "addJS"
              }
            ],
            // 列表api
            listApi: {
              url: "/appcloud-portal/role/listRole",
              type: "POST",
              params:{
          
              }
            },
            // 表头设置
            header: [
              {
                label: "ID",
                propName: "id",
                align: "left"
              },
              {
                label: "角色名",
                propName: "roleName"
              },
              {
                label: "备注",
                propName: "description"
              },
              // {
              //   label: "权限",
              //   propName: "strong"
              // },
              {
                label: "操作",
                propName: "strong",
                btns: [ {
                      label: "编辑",
                      commandName: "editjs",
                    },{
                      label: "删除",
                      commandName: "deletejs"
                    },
                ]
              }
            ]
          }
        }
      }
    },
    mounted() {
      this.$refs.listTpml.refresh()
    },
    methods:{
      handleCommand(command,row,index){
        console.log(command,row,index)
        if(command&&this[command]){
          this[command](row,index)
        }
      },
      refresh(){
        this.$refs.listTpml.refresh()
      },
      // 新增角色
      addJS(){
        this.$refs.addjs.open(false)
      },
      // 修改角色
      editjs(row){
        this.$refs.addjs.open(true,row)
      },
      deletejs(row){
        this.$confirm('确定要删除该角色?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteRole(row.id).then(ret=>{
            if(ret&&ret.code == 0){
              this.$message({type: 'success',message: '删除成功!'})
              this.refresh()
            }else{
              this.$message({type: 'error',message: '删除失败!'})
            }
          })
        })
      },

    }
  }
</script>
